package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.TenantClient;
import com.salt.admin.api.model.MultiTenant;
import com.salt.admin.api.model.User;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author salt
 * @Date 2022/1/21
 * @Version 1.0.1
 */
@Slf4j
@Component
public class TenantClientHystrix implements FallbackFactory<TenantClient> {

    @Override
    public TenantClient create(Throwable throwable) {
        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);
        return new TenantClient() {
            @Override
            public MultiTenant find() {
                return null;
            }

            @Override
            public MultiTenant findByUser(User user) {
                return null;
            }
        };
    }
}
